package com.jc.demo.hadoop.yarn.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import java.util.Map;

/**
 * 由于Hadoop执行时需要指定很多参数（或者叫选项），所以使用辅助类GenericOptionsParser来填充没指定的参数（或者叫选项）
 *
 * 但不是直接使用GenericOptionsParser类，而是通过ToolRunner，ToolRunner内部会调用GenericOptionsParser
 */
public class ConfigurationPrinter extends Configured implements Tool {

    static {
        Configuration.addDefaultResource("hadoop-local.xml");
    }


    @Override
    public int run(String[] args) throws Exception {
        Configuration conf = getConf();
        for (Map.Entry<String, String> entry : conf) {
            System.out.printf("%s=%s\n", entry.getKey(), entry.getValue());
        }

        return 0;
    }

    public static void main(String[] args) throws Exception {
        int exitCode = ToolRunner.run(new ConfigurationPrinter(), args);
        System.exit(exitCode);

    }
}
